package com.zscat.mallplus.sys.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zscat.mallplus.annotation.SysLog;
import com.zscat.mallplus.dms.entity.DmsOrder;
import com.zscat.mallplus.dms.service.IDmsOrderService;
import com.zscat.mallplus.enums.OrderStatus;
import com.zscat.mallplus.enums.TaskType;
import com.zscat.mallplus.qsg.*;
import com.zscat.mallplus.qsg.mapper.QsgDeviceTaskMapper;
import com.zscat.mallplus.qsg.service.*;
import com.zscat.mallplus.sys.entity.SysUser;
import com.zscat.mallplus.ums.entity.UmsAdminMember;
import com.zscat.mallplus.util.DateUtil;
import com.zscat.mallplus.util.UserUtils;
import com.zscat.mallplus.utils.CommonResult;
import com.zscat.mallplus.utils.ValidatorUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

@Slf4j
@RestController
@Api(tags = "UmsAdminMemberController", description = "绑定用户管理")
@RequestMapping("/admin/sys/adminmember")
public class UmsAdminMemberController {

    @Resource
    private IUmsAdminMemberService adminMemberService;

    @SysLog(MODULE = "qsg", REMARK = "根据条件查询所有绑定用户列表")
    @ApiOperation("根据条件查询所有绑定用户列表")
    @GetMapping(value = "/list")
    public Object getDeviceByPage(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                  @RequestParam(value = "pageSize", defaultValue = "30") Integer pageSize
    ) {
        QueryWrapper qw = new QueryWrapper();
        qw.orderByDesc("create_time");
        qw.eq("store_id",UserUtils.getCurrentMember().getQsgStoreId());
        try {
            IPage<UmsAdminMember> devices = adminMemberService.page(new Page<>(pageNum, pageSize), qw);
            return new CommonResult().success(devices);
        } catch (Exception e) {
            log.error("根据条件查询所有绑定账号列表：%s", e.getMessage(), e);
        }
        return new CommonResult().failed();
    }

    @SysLog(MODULE = "sys", REMARK = "删除绑定用户列表")
    @ApiOperation("删除用户绑定用户列表")
    @GetMapping(value = "/delete/{id}")
    public Object deleteAdminMember(@ApiParam("用户id") @PathVariable Long id) {
        try {
            if (ValidatorUtils.empty(id)) {
                return new CommonResult().paramFailed("用户id");
            }
            adminMemberService.removeById(id);
            return new CommonResult().success();
        } catch (Exception e) {
            log.error("删除用户：%s", e.getMessage(), e);
            return new CommonResult().failed();
        }
    }

}
